In the event of technical difficulties with Szkopuł, please contact us via email at szkopul@fri.edu.pl.
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
A permutation of elements is a one-to-one function (injection)
. An order of permutation
is the minimal
, such that for all
we have:
i.e. composed with itself
times becomes identity function. For example, the order of the permutation of
elements
is
, because
.
For a given let us consider permutations of
-elements having the the largest order possible. For example, the maximal order of a permutation of
elements is
. An example of a permutation of
elements whose order is
is
.
Among all permutations of elements having the maximal order, we would like to find the earliest one (in a lexicographical order). Being more precise, we say a permutation
of
elements is earlier than a permutation
of
elements, if there exists
, such that
for all
and
. The earliest permutation of
elements having an order
is
.
Write a programme that:
There is one positive integer in the first line of the standard input,
. In the following
lines there are positive integers
, one per line,
.
Your programme should write lines to the standard output. The
'th line should contain a sequence of integers separated by spaces, forming the least permutation of
elements having the maximal order, i.e. the sequence
, where
denotes this permutation.
For the input data:
2 5 14
the correct result is:
2 1 4 5 3 2 3 1 5 6 7 4 9 10 11 12 13 14 8
Task author: Jakub Pawlewicz.